package com.hualan.sfzy.service.course.serviceimpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.entity.course.CourseStore;
import com.hualan.sfzy.mapper.course.CourseStoreMapper;
import com.hualan.sfzy.service.course.CourseStoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CourseStoreServiceImpl implements CourseStoreService {
    @Autowired
    private CourseStoreMapper courseStoreMapper;
    @Override
    public int add(CourseStore courseStore) {
        return courseStoreMapper.insert(courseStore);
    }

    @Override
    public int edit(CourseStore courseStore) {
        return courseStoreMapper.update(courseStore);
    }

    @Override
    public int remove(Integer id) {
        return courseStoreMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return courseStoreMapper.deleteBatch(ids);
    }

    @Override
    public List<CourseStore> find() {
        return courseStoreMapper.select(null);
    }

    @Override
    public CourseStore findById(Integer id) {
        return courseStoreMapper.selectById(id);
    }

    @Override
    public Map<String, Object> findByPage(Integer pageNum, Integer pageSize, CourseStore courseStore) {
        PageHelper.startPage(pageNum,pageSize);
        List<CourseStore> list = courseStoreMapper.select(courseStore);
        PageInfo<CourseStore> pageInfo = new PageInfo<CourseStore>(list);
        Map<String, Object> map = new HashMap<>();
        map.put(CommonConstant.PAGE_LIST, list);
        map.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());
        map.put(CommonConstant.TOTAL, pageInfo.getTotal());
        return map;
    }

    @Override
    public int countByCourseId(Integer courseId) {
        return courseStoreMapper.countByCourseId(courseId);
    }

    @Override
    public Integer checkCollection(Integer userId, Integer courseId) {

        return courseStoreMapper.checkCollection(userId, courseId) ;
    }

    @Override
    public int deleteByUserAndCourse(Integer userId, Integer courseId) {
        return courseStoreMapper.deleteByUserAndCourse(userId, courseId);
    }


}

